//
//  ScenicStoryVM.swift
//  LeTu
//
//  Created by g1 on 2024/1/13.
//

import Foundation

class ScenicStoryVM {
    
    private(set) var scenicModel: ScenicModel
    var storyModel: ScenicStoryModel
    var currentClassifysIndex: Int = 0
    
    init(scenicModel: ScenicModel, storyModel: ScenicStoryModel, currentClassifysIndex: Int) {
        self.scenicModel = scenicModel
        self.storyModel = storyModel
        self.currentClassifysIndex = currentClassifysIndex
    }
    
    // MARK: - 获取景区详情
    func getScenicDetails(completeHandle: @escaping NetworkRequestHandle) {
        
        apiProvider.request(api: .getScenicDetails(Int32(scenicModel.id))) { [weak self] json, jsonArr, code in
            
            MYLog("获取景区详情：",json)
            
            var dialog = DialogMessage()
            guard let strongSelf = self,let pm = Mapper<ResponseModel>().map(JSON: json), code == 200 else { return completeHandle(dialog) }
            dialog.code = pm.code
            dialog.message = pm.msg
            guard pm.code == 200, let data = pm.data as? [String: Any], let model = Mapper<ScenicModel>().map(JSON: data) else {
                completeHandle(dialog)
                return
            }
            
            strongSelf.scenicModel = model
            completeHandle(dialog)
            
        } failureHandler: { error in
            completeHandle(DialogMessage())
        }
        
    }
    
}
